home *** CD-ROM | disk | FTP | other *** search
/ DarkBASIC - The Ultimate 3D Game Creator / PCactive 8 CD1 - DarkBasic.iso / SOFTWARE / DEMOS / DarkForge2000 / snippets_vol4 / snip_puretextscroller.dba < prev    next >
Encoding:
Text File  |  2000-10-17  |  4.4 KB  |  194 lines

  1. `    ------------------------------------------------------------------------
  2. `    Pure Text Scroller                        DarkForge Snippet (12/10/2000)
  3. `    ------------------------------------------------------------------------
  4. `    This routine is nice, fast, works in whatever resolution you want and
  5. `    creates a cool, fast scroller using text only (no external graphics)
  6. `    Infact it's fast enough to have the entire screen full of scrollers!
  7. `    See further down the code for the line to change to make this work.
  8.  
  9. hide mouse
  10. sync rate 0
  11. sync on
  12.  
  13. `    Make our font set (uses the Courier font 10x12 pixels)
  14.  
  15. set text font "Courier"
  16. set text size 10
  17.  
  18. sw = screen width()
  19. sh = screen height()
  20. cps = sw/10
  21.  
  22. create bitmap 2,sw,sh
  23.  
  24. x=0 : y=0
  25.  
  26. for a=32 to 122
  27.  
  28. `    Uncomment these 4 lines for a better looking "wind-swept" font
  29.  
  30. `    ink rgb(0,100,0),0
  31. `    text x+2,y,chr$(a)
  32. `    ink rgb(0,175,0),0
  33. `    text x+1,y,chr$(a)
  34.  
  35.     ink rgb(0,255,0),0
  36.     text x,y,chr$(a)
  37.  
  38.     inc x,10
  39.  
  40.     if x=>sw
  41.         inc y,12
  42.             x=0
  43.     endif
  44.  
  45. next a
  46.  
  47. `    Grab the font into images. We're using image numbers 32 to 122 so they
  48. `    map to the ASCII values. It's lazy but it works faster.
  49.  
  50. x=0 : y=0
  51.  
  52. for a=32 to 122
  53.     get image a,x,y,x+10,y+12
  54.     inc x,10
  55.     if x=>sw
  56.         inc y,14
  57.         x=0
  58.     endif
  59. next a
  60.  
  61. cls 0
  62.  
  63. `    Get the size of the scroll text data
  64.  
  65. restore scrolltext
  66. scroll_lines = 0
  67. scroll_length = 0
  68.  
  69. repeat
  70.     read temp$
  71.     inc scroll_lines
  72.     scroll_length = scroll_length + len(temp$)
  73. until temp$=" "
  74.  
  75. `    Read the text into an array called s$()
  76.  
  77. restore scrolltext
  78.  
  79. dim s$(scroll_length+cps)
  80. a=0
  81.  
  82. repeat
  83.  
  84.     read temp$
  85.  
  86.     for b=0 to len(temp$)
  87.         temp_char$=mid$(temp$,b)
  88.         s$(a)=temp_char$
  89.         inc a
  90.     next b
  91.  
  92. until temp$=" "
  93.  
  94. `    That's the text sorted. Now let's display it
  95.  
  96. set text opaque
  97. create bitmap 1,sw,sh
  98.  
  99. sl=scroll_length+cps
  100. x1#=sw
  101. x2#=sw+sw
  102. speed#=4
  103.  
  104. pointer=MakeLine(1,0,cps,sl)
  105. pointer=MakeLine(2,pointer,cps,sl)
  106.  
  107. `    Set "texts" to 1 or 0, 1 is a single scroller, 0 is 30!
  108.  
  109. texts=0
  110.  
  111. do
  112.  
  113.     if texts=1
  114.         paste image 1,x1#,0
  115.         paste image 2,x2#,0
  116.     else
  117.         for a=0 to sh step 15
  118.             paste image 1,x1#,a
  119.             paste image 2,x2#,a
  120.         next a
  121.     endif
  122.  
  123.     dec x1#,speed#
  124.     dec x2#,speed#
  125.  
  126.     neg_sw#=1-(sw+1)
  127.  
  128.     if x1#=<neg_sw#
  129.         pointer=MakeLine(1,pointer,cps,sl)
  130.         x1#=sw
  131.     endif
  132.  
  133.     if x2#=<neg_sw#
  134.         pointer=MakeLine(2,pointer,cps,sl)
  135.         x2#=sw
  136.     endif
  137.  
  138. `    Uncomment for the FPS
  139. `    text 0,0,str$(screen fps())
  140.  
  141.     copy bitmap 1,0
  142.     sync
  143.  
  144. loop
  145.  
  146.  
  147.  
  148. `    - DF Function --------------------------------------------------------
  149. `    This creates the next image (i) of text, c=current position
  150. `    -------------------------------------------------------- DF Function -
  151.  
  152. function MakeLine(i,c,cps,sl)
  153.  
  154.     set current bitmap 2
  155.  
  156.     for a=0 to cps-1
  157.         t$=s$(c)
  158.         pi=asc(t$)
  159.         if pi=0 then pi=32
  160.         paste image pi,a*10,0
  161.         inc c
  162.         if c>sl then c=0
  163.     next a
  164.  
  165.     get image i,0,0,screen width(),13
  166.     cls 0 : set current bitmap 1
  167.  
  168. endfunction c
  169.  
  170. `    - DF Data ------------------------------------------------------------
  171. `    The actual data, terminate with a single space on its own
  172. `    ------------------------------------------------------------ DF Data -
  173.  
  174. scrolltext:
  175. data "DARKFORGE PRESENT TO YOU A COMPLETE TEXT-BASED SCROLLER THAT"
  176. data "DOES NOT NEED ANY EXTERNAL GRAPHICS FILES! IT'S ALSO FAST AND"
  177. data "SMOOTH SO NO WORRIES ABOUT CPU OVERHEAD HERE :-) "
  178. data "THIS ONE WAS A TRIAL TO SEE HOW MANY LITTLE SCROLLERS I COULD"
  179. data "GET ON-SCREEN AT ONCE AND I AM QUITE HAPPY WITH THE RESULTS! NO LESS"
  180. data "THAN 30 OF THE SUCKERS AND ALL MOVING AT A DECENT FRAME RATE."
  181. data "IF YOU CAN'T SEE 30 OF THEM, THEN FIND THE TEXTS VALUE AND ALTER IT"
  182. data "QUICKLY! IT LOOKS REALLY NICE WITH LOTS OF THINGS GOING ON :-) ..."
  183. data "GOD I LOVE DARKBASIC SOMETIMES, AND TO ALL THOSE WHO SAY IT CAN'T"
  184. data "HACK IT AT 2D - SCREW YOU! YOU'RE JUST NOT AS GOOD AS ME ;-)"
  185. data "  ... OKAY SOME GREETINGS I THINK ... HELLO TO THE FOLLOWING PEOPLE"
  186. data "- TRACER FOR YOUR DOTS DUDE, ASMPROGRAMMER FOR YOUR BETA TESTING,"
  187. data "BIGGUN FOR YOUR COOL GRAPHICS FX, PJAY FOR JUST BEING COOL, SI FOR"
  188. data "HIS TRIPPY LITTLE SHEEP GAME, ALL THOSE ON THE DB FORUMS WHO AREN'T"
  189. data "CALLED ANTHONY (OR WHO GO ON ENDLESSLY ABOUT BLITZ, TAKE IT ELSEWHERE"
  190. data "PEOPLE, WE DON'T GIVE A SHIT!) AND WELL GENERALLY HI TO YOU TOO..."
  191. data "OKAY LET'S WRAP THIS SUCKER, IT'S FAR TOO LONG ALREADY....... WRAP!"
  192. data " "
  193.  
  194.